package parser;

import antlr.RecognitionException;
import antlr.Token;
import java.util.List;

class SpecialExpr extends Expr {

    Expr expr;
    int name;

    SpecialExpr(Expr expr, int name) {
        this.name = name;
        this.expr = expr;
    }

    void write(ByteStream out) throws RecognitionException {
        expr.write(out);
        if (name > 255) {
            throw new RecognitionException("Special attribute is not a standard name");
        }
        if (name == StandardNames.type) {
            out.write(Opcodes.TYPE);
        } else {
            out.write(Opcodes.LOAD_SPECIAL);
            out.write(name);
        }
    }

    void writeLHS(ByteStream out) throws RecognitionException {
        throw new RecognitionException("Cannot assign to special attribute");
    }

    void delete(ByteStream out) throws RecognitionException {
        throw new RecognitionException("Cannot assign to special attribute");
    }

    void writeAugAsgn(int op, Expr value, ByteStream out) throws RecognitionException {
        throw new RecognitionException("Cannot assign to special attribute");
    }
}
